package GUIHelper;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ControlLayer.RoomBookingCtr;
import ControlLayer.RoomBookingLine_RoomCtr;
import GUILayer.SaleGUI;

public class CheckOutFrame {
	private JFrame frame;
	private SaleGUI saleGUI;
	private int rbId;
	private RoomBookingCtr rbCtr;
	private RoomBookingLine_RoomCtr rbl_rCtr;

	public CheckOutFrame(JPanel panel, int rbId) {
		this.rbId = rbId;
		saleGUI = (SaleGUI) panel;
		frame = new JFrame("Check Out");
		frame.setSize(300, 150);
		frame.setLocationRelativeTo(null);
		initialize();
	}

	public void initialize() {
		rbl_rCtr = new RoomBookingLine_RoomCtr();
		rbCtr = new RoomBookingCtr();

		JPanel mainPanel = new JPanel();
		frame.getContentPane().add(mainPanel);
		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

		JPanel infoPanel = new JPanel();
		infoPanel.setLayout(new FlowLayout());

		JLabel lblinfo = new JLabel("Please input room Id");
		final JTextField textField_rId = new JTextField();
		textField_rId.setColumns(10);
		infoPanel.add(lblinfo);
		infoPanel.add(textField_rId);
		mainPanel.add(infoPanel);

		JPanel choicePanel = new JPanel();
		choicePanel.setLayout(new FlowLayout());
		JButton btnOK = new JButton("OK");
		JButton btnCancel = new JButton("Cancel");
		choicePanel.add(btnOK);
		choicePanel.add(btnCancel);

		mainPanel.add(choicePanel);

		btnOK.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// TODO check out room and guests
				rbCtr.checkOut(Integer.parseInt(textField_rId.getText()));
				rbl_rCtr.deleteRoomForRBL(Integer.parseInt(textField_rId.getText()));
				saleGUI.showRBTable(rbId);
				frame.dispose();
			}
		});

		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
	}

	public JFrame getFrame() {
		return frame;
	}

	public void setFrame(JFrame frame) {
		this.frame = frame;
	}

}
